package com.yy.controller.admin;

import com.yy.controller.mapper.SetmealDishMapper;
import com.yy.controller.mapper.SetmealMapper;
import com.yy.controller.service.SetmealService;
import com.yy.dto.SetmealPageQueryDTO;
import com.yy.entity.Setmeal;
import com.yy.entity.SetmealDish;
import com.yy.result.PageResult;
import com.yy.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
@Slf4j
@Api(tags = "套餐管理接口")
public class SetmealController {
   @Autowired
    private SetmealService setmealService;
   @Autowired
    private SetmealDishMapper setmealDishMapper;

    /**
     * 分页条件查询套餐列表
     * @param setmealPageQueryDTO
     * @return
     */
   @GetMapping("/list")
   @CrossOrigin
   @ApiOperation("分页条件查询套餐列表")
   public Result pageList(SetmealPageQueryDTO setmealPageQueryDTO){
       PageResult pageResult=setmealService.pageList(setmealPageQueryDTO);
       return Result.success(pageResult);
   }

    /**
     * 根据id删除套餐
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @CrossOrigin
    @ApiOperation("根据id删除套餐")
    public  Result delete(@PathVariable Long id){
        setmealService.delete(id);
        return Result.success();
    }

    /**
     * 新增套餐
     * @param setmeal
     * @return
     */
    @PostMapping("/add")
    @CrossOrigin
    @ApiOperation("新增套餐")
    public  Result add(@RequestBody Setmeal setmeal){
        setmealService.add(setmeal);
        return Result.success();
    }

    /**
     * 修改套餐
     * @param setmeal
     * @return
     */
    @PutMapping("/update")
    @CrossOrigin
    @ApiOperation("修改套餐")
    public Result update(@RequestBody Setmeal setmeal){
        setmealService.update(setmeal);
        return Result.success();
    }
    @GetMapping("/setmealDsihList/{id}")
    @CrossOrigin
    @ApiOperation("根据id获取套餐菜品关联表")
    public Result<List<SetmealDish>> getSetmealDsihListById(@PathVariable Long id){
        List<SetmealDish> setmealDishList=setmealDishMapper.getbySetmealId(id);
        return Result.success(setmealDishList);
    }

}
